package com.salinity.kun.algorithm.harmonic;

import java.util.Date;
import com.salinity.kun.algorithm.harmonic.AvgEclipticLongitude.ELSymbol;

public class InitialPhase {

	private Date date;
	private TideSymbol tideSymbol;
	private double s, h1, p, N1, p1, t1, V0;
	private AvgEclipticLongitude AELongitude;

	public InitialPhase() {

	}

	public InitialPhase(TideSymbol tideSymbol) {
		this.tideSymbol = tideSymbol;
	}

	public InitialPhase(Date date, TideSymbol tideSymbol) {
		this.tideSymbol = tideSymbol;
		this.setTime(date);

	}

	private void calParams() {
		if (date == null) {
			throw new RuntimeException("must set date when calculating initial phase!");
		}
		if (tideSymbol == null) {
			throw new RuntimeException("must set date when calculating initial phase!");
		}
		AELongitude = new AvgEclipticLongitude(date);
		setS(AELongitude.getAELongitude(ELSymbol.s));
		setH1(AELongitude.getAELongitude(ELSymbol.h));
		setP(AELongitude.getAELongitude(ELSymbol.p));

		// 资料
		// setN1(100.84 + 19.3282 * (Y - 1900) + 0.0530 * days);

		// 《潮汐学》，陈宗镛
		setN1(AELongitude.getAELongitude(ELSymbol.N));
		setP1(AELongitude.getAELongitude(ELSymbol.p1));
		setT1(AELongitude.getAELongitude(ELSymbol.t1));
		int[] doodson = ConstantParamHelper.getDoodson().get(tideSymbol);
		setV0(doodson[0] * t1 + doodson[1] * s + doodson[2] * h1 + doodson[3] * p + doodson[4] * N1 + doodson[5] * p1
				+ doodson[6] * 90);
	}

	public Date getTime() {
		return date;
	}

	public void setTime(Date date) {
		this.date = date;
		if (this.tideSymbol != null) {
			calParams();
		}
	}

	public TideSymbol getTideSymbol() {
		return tideSymbol;
	}

	public void setTideSymbol(TideSymbol tideSymbol) {
		this.tideSymbol = tideSymbol;
		if (this.date != null) {
			calParams();
		}
	}

	/**
	 * 单位：°
	 * 
	 * @return
	 */
	public double getS() {
		return s;
	}

	/**
	 * 单位：°
	 * 
	 * @return
	 */
	private void setS(double s) {
		this.s = s;
	}

	/**
	 * 单位：°
	 * 
	 * @return
	 */
	public double getH1() {
		return h1;
	}

	/**
	 * 单位：°
	 * 
	 * @return
	 */
	private void setH1(double h1) {
		this.h1 = h1;
	}

	/**
	 * 单位：°
	 * 
	 * @return
	 */
	public double getP() {
		return p;
	}

	/**
	 * 单位：°
	 * 
	 * @return
	 */
	private void setP(double p) {
		this.p = p;
	}

	/**
	 * 单位：°
	 * 
	 * @return
	 */
	public double getN1() {
		return N1;
	}

	/**
	 * 单位：°
	 * 
	 * @return
	 */
	private void setN1(double n1) {
		N1 = n1;
	}

	/**
	 * 单位：°
	 * 
	 * @return
	 */
	public double getP1() {
		return p1;
	}

	/**
	 * 单位：°
	 * 
	 * @return
	 */
	private void setP1(double p1) {
		this.p1 = p1;
	}

	/**
	 * 单位：°
	 * 
	 * @return
	 */
	public double getT1() {
		return t1;
	}

	/**
	 * 单位：°
	 * 
	 * @return
	 */
	private void setT1(double t1) {
		this.t1 = t1;
	}

	/**
	 * 单位：°
	 * 
	 * @return
	 */
	public double getV0() {
		return V0;
	}

	private void setV0(double v0) {
		V0 = v0;
	}

}
